const express = require('express');


const app = express();

const fs=require('fs');
const path=require('path');
function recordMiddleware(req,res, next){
      if(req.query.code == '521'){
            next()
      }else{
            res.send('暗号错误')
      }
      // let {url, ip} = req;
      // fs.appendFileSync( path.resolve(__dirname,'./access.log'),  `${url}: ${ip}\r\n` );
      // next();
}

// app.use(recordMiddleware);

app.get('/home',recordMiddleware, (req,res)=>{
      // let {url, ip} = req;
      // console.log('url=>',url);
      // console.log('path=>',path.resolve(__dirname,'./access.log' ));
      // fs.appendFileSync( path.resolve(__dirname,'./access.log'),  `${url}: ${ip}` );

      // res.set('aaa','bbbs');
      // res.status(500)
      // console.log('ip=>',ip)

      res.send('前台首页')
})

app.get('/admin',recordMiddleware,(req,res)=>{
      res.send('后台首页')
})

app.get('/setting',recordMiddleware,(req,res)=>{
      res.send('setting首页')
})


app.listen(3000,()=>{
      console.log('启动')
})

app.all('*',(req,res)=>{
      res.send(`<h1> 404 not found </h1>`)
})
